package com.pybox.oauth.conf;


import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.List;

@Data
public class UserDto implements UserDetails {


    @ApiModelProperty("id")
    private int id;

    @ApiModelProperty("用户账号")
    private String username;

    @ApiModelProperty("客户id")
    private Integer customerId;

    @ApiModelProperty("员工姓名")
    private String realname;

    @ApiModelProperty("密码")
    private String password;

    @ApiModelProperty("手机号")
    private String phone;

    @ApiModelProperty("邮箱")
    private String email;

    @ApiModelProperty("0：正常；1：禁用")
    private Integer state;

    @ApiModelProperty("deleted：1删除 ，0 正常")
    private Integer deleted;

    @ApiModelProperty("是否是管理员 0，默认管理员 1 管理员 2 普通用户")
    private Integer isAdmin;

    private List<GrantedAuthority> authorities;

    @Override
    public String getUsername() {
        return this.getRealname();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        if (this.getState()==1 && this.getIsAdmin() ==2){
            return false;
        }
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
